/** 前端类型定义 */

// 用户相关
export interface User {
  user_id: string
  username: string
  email: string
  nickname?: string
  learning_style?: string
}

// 评估相关
export interface AssessmentResult {
  assessment_id: string
  status: string
  results: {
    legal_basics: number
    thinking_rigor: number
    answer_speed: number
    knowledge_breadth: number
  }
}

export interface LearningStyleResult {
  user_id: string
  learning_style: string
  preferences: {
    content_type: string[]
    difficulty: string
    feedback: string
  }
}

export interface WeaknessAnalysis {
  user_id: string
  weak_areas: Array<{
    area: string
    score: number
    priority: string
  }>
  recommendations: string[]
}

export interface StudyPlan {
  user_id: string
  plan_id: string
  duration_days: number
  daily_targets: {
    study_hours: number
    questions: number
    review_time: number
  }
  phases: Array<{
    phase: number
    name: string
    duration: number
  }>
}

// 训练相关
export interface TrainingSession {
  session_id: string
  user_id: string
  plan_id?: string
  status: string
  started_at: string
}

export interface Question {
  question_id: string
  session_id: string
  content: string
  options: string[]
  type: string
  difficulty: string
  knowledge_points: string[]
  category?: string
  subject?: string
  is_completed?: boolean  // 是否已完成所有题目
}

export interface AnswerSubmission {
  session_id: string
  question_id: string
  is_correct: boolean
  user_answer: string
  correct_answer: string
  explanation: string
  score: number
  time_spent: number
  detailed_analysis?: string | {
    detailed_analysis?: string
    thinking_approach?: string
    correct_answer_explanation?: string
    error_analysis?: string
    knowledge_points?: string[]
    reinforcement_suggestions?: string[]
  }  // 详细分析（答对时：做题思路和为什么正确；答错时：错误分析）
  detailed_error_analysis?: any  // 详细错误分析（答错时）
}

export interface ErrorAnalysis {
  session_id: string
  question_id: string
  error_type: string
  error_category: string
  error_details: {
    mistaken_concept?: string
    correct_concept?: string
  }
  recommendations: string[]
}

// 进度相关
export interface ProgressOverview {
  user_id: string
  total_study_days: number
  total_study_hours: number
  total_questions: number
  total_correct?: number
  total_wrong?: number
  current_streak: number
  longest_streak: number
  overall_accuracy: number
  error_rate?: number
  accuracy_trend: Array<{
    date: string
    accuracy: number
  }>
}

export interface PerformanceMetrics {
  user_id: string
  period: string
  metrics: {
    accuracy_rate: number
    average_time_per_question: number
    thinking_quality_score: number
    improvement_rate: number
  }
  daily_stats: Array<{
    date: string
    questions_answered: number
    correct_answers: number
    accuracy: number
    study_duration: number
  }>
}

export interface VisualizationData {
  user_id: string
  knowledge_heatmap: Record<string, {
    score: number
    practice_count: number
  }>
  thinking_radar: {
    logical_reasoning: number
    case_analysis: number
    legal_application: number
    speed: number
    accuracy: number
  }
  learning_curve: Array<{
    date: string
    cumulative_accuracy: number
  }>
}

export interface Achievement {
  achievement_id: string
  name: string
  description: string
  icon: string
  unlocked_at?: string
  progress?: number
}

// 分析相关
export interface ErrorAttribution {
  user_id: string
  analysis_date: string
  error_distribution: {
    knowledge: {
      count: number
      percentage: number
      examples: Array<{
        question_id: string
        error: string
        category: string
      }>
    }
    thinking: {
      count: number
      percentage: number
      examples: Array<{
        question_id: string
        error: string
        category: string
      }>
    }
    technique: {
      count: number
      percentage: number
      examples: Array<{
        question_id: string
        error: string
        category: string
      }>
    }
    attention: {
      count: number
      percentage: number
      examples: Array<{
        question_id: string
        error: string
        category: string
      }>
    }
  }
  recommendations: string[]
}

export interface AccuracyPrediction {
  user_id: string
  current_accuracy: number
  prediction_days: number
  predicted_accuracy: number
  confidence_interval: {
    lower: number
    upper: number
  }
  learning_curve: Array<{
    day: number
    predicted_accuracy: number
  }>
}

export interface WeeklyGoal {
  week: number
  target_accuracy: number
  actual_accuracy: number | null
  status: string
}

export interface ImprovementRecommendation {
  type: string
  title: string
  description: string
  priority: string
  estimated_time: string
}

export interface AccuracyStatistics {
  user_id: string
  period: string
  overall_accuracy: number
  accuracy_by_category: Record<string, number>
  accuracy_trend: {
    daily: Array<{
      date: string
      accuracy: number
    }>
    weekly: Array<{
      week: number
      accuracy: number
    }>
  }
  improvement_rate: number
}

// 模拟测试相关
export interface MockExam {
  exam_id: string
  user_id: string
  exam_type: string
  name: string
  question_count: number
  time_limit: number
  question_ids: string[]
  started_at: string
  status: string
}

export interface ExamResult {
  exam_id: string
  user_id: string
  total_questions: number
  correct_count: number
  accuracy: number
  time_spent: number
  submitted_at: string
  subject_scores: Record<string, number>
  knowledge_stage: {
    main_stage: {
      key: string
      name: string
      score_range: [number, number]
      description: string
      advice: string
      icon: string
    }
    overall_score: number
    strong_subjects: Array<{
      subject: string
      accuracy: number
    }>
    weak_subjects: Array<{
      subject: string
      accuracy: number
    }>
    assessment_date: string
  }
  detailed_results: Array<{
    question_id: string
    user_answer: string
    correct_answer: string
    is_correct: boolean
    subject: string
    knowledge_points: string[]
  }>
  recommendations: string[]
}

// 法律思维训练相关
export interface ThinkingAnalysis {
  thinking_quality_score: number
  strengths: string[]
  weaknesses: string[]
  thinking_pattern: string
  reasoning_chain: {
    major_premise: {
      type: string
      provisions: string[]
      description: string
    }
    minor_premise: {
      type: string
      facts: string[]
      description: string
    }
    conclusion: {
      type: string
      content: string
      description: string
    }
    reasoning_completeness: {
      score: number
      has_major_premise: boolean
      has_minor_premise: boolean
      has_conclusion: boolean
      level: string
    }
  }
  key_facts: Array<{
    type: string
    text: string
    keyword: string
    importance: string
  }>
  legal_entities: Array<{
    type: string
    text: string
    start: number
    end: number
  }>
  improvement_suggestions: string[]
  legal_knowledge_gaps: string[]
  analysis_timestamp: string
  bert_enhanced?: boolean
}

export interface ThinkingFeedback {
  feedback_text: string
  suggestions: string[]
  encouragement: boolean
  bert_insights?: {
    reasoning_chain: any
    key_facts: any[]
    traps: any[]
    reasoning_completeness: any
  }
  error?: string
}

export interface QuestionStructure {
  question_type: string
  keywords: {
    time词?: string[]
    主体词?: string[]
    行为词?: string[]
    结果词?: string[]
  }
  difficulty: string
  legal_domain: string
  has_case: boolean
  has_provision: boolean
  structure: {
    has_background: boolean
    has_condition: boolean
    has_question: boolean
  }
  option_analysis?: any
  suggestions: string[]
}

export interface ReasoningGuidance {
  reasoning_chain: any
  key_facts: any[]
  traps: any[]
  guidance: {
    next_steps: string[]
    warnings: string[]
  }
}

export interface TechniqueAnalysis {
  strategy: {
    overall_strategy: string
    step_by_step: string[]
    time_management: {
      suggested_time_seconds: number
      breakdown: {
        审题: number
        分析: number
        选择: number
        检查: number
      }
      tips: string[]
    }
    common_mistakes: string[]
  }
  keywords: {
    keywords: any
    keyword_importance: any
    total_keywords: number
    analysis: string
  }
  traps: {
    traps: any[]
    option_traps: any[]
    summary: {
      total_traps: number
      high_severity: number
      medium_severity: number
      risk_level: string
    }
    prevention_tips: string[]
  }
  option_analysis: {
    similarity_analysis: any
    option_features: any
    exclusion_suggestions: any[]
    comparison_strategy: string
  }
}

// 辩论训练相关
export interface DebateSession {
  debate_id: string
  user_id: string
  question_id: string
  question_content: string
  question_options?: string[]
  user_position: string
  status: 'active' | 'ended'
  rounds: DebateRound[]
  started_at: string
  current_round: number
  evaluation?: DebateEvaluation
  ended_at?: string
}

export interface DebateRound {
  round: number
  user_argument: string
  ai_response: string
  ai_role: string
  argument_analysis?: {
    key_facts: any[]
    legal_entities: any[]
    reasoning_chain: any
    argument_length: number
    has_legal_provisions: boolean
  }
  timestamp: string
}

export interface DebateEvaluation {
  argument_quality: number
  logical_rigor: number
  legal_accuracy: number
  reasoning_completeness: number
  key_facts_count: number
  legal_provisions_count: number
  total_rounds: number
  improvement_suggestions: string[]
  summary: string
  evaluated_at: string
}

export interface DebateArgumentResult {
  debate_id: string
  round: number
  user_argument: string
  ai_response: {
    response_text: string
    role: string
    round: number
    suggestions: string[]
    timestamp: string
  }
  argument_analysis: any
  debate_status: string
  is_final_round: boolean
}

